package com.wty.controller;

import com.wty.annotation.RoutingDataSource;
import com.wty.common.DataSources;
import com.wty.dao.userInfoMapper;
import com.wty.pojo.userInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author wangtengyu
 * @Create 2018-08-31-8:36
 */
@RestController
public class TestController {

    @Autowired
    private userInfoMapper userInfomapper;

    @PostMapping("/add")
    @RoutingDataSource(DataSources.MASTER_DB)
    public String add(userInfo user){

        int result= userInfomapper.insert(user);
        if(result>0){
            return "插入信息成功"+user.getId();
        }
        return "插入信息失败";
    }



    @GetMapping("/get/{id}")
    @RoutingDataSource(DataSources.SLAVE_DB)
    public userInfo get(@PathVariable("id") Integer id){
        userInfo userInfo= userInfomapper.selectByPrimaryKey(id);
        return userInfo;
    }

}
